package com.nageoffer.shortlink.admin.controller;

import com.nageoffer.shortlink.admin.common.convention.result.Result;
import com.nageoffer.shortlink.admin.common.convention.result.Results;
import com.nageoffer.shortlink.admin.pojo.dto.req.ShortLinkGroupSortReqDTO;
import com.nageoffer.shortlink.admin.pojo.dto.req.ShortLinkGroupUpdateDTO;
import com.nageoffer.shortlink.admin.pojo.dto.req.ShortLinkGroupSaveReqDTO;
import com.nageoffer.shortlink.admin.pojo.dto.resp.ShortLinkGroupRespDTO;
import com.nageoffer.shortlink.admin.service.GroupService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/short-link/admin/v1/group")
public class GroupController {

    private final  GroupService groupService;

    /**
     * 新增分组
     * @param requestParam
     * @return
     */
    @PostMapping
    public Result<Void> save(@RequestBody ShortLinkGroupSaveReqDTO requestParam){
        groupService.saveGroup(requestParam);
        return Results.success();
    }


    /**
     * 查询短链接分组
     * @return
     */
    @GetMapping
    public Result<List<ShortLinkGroupRespDTO>> listGroup(){
        List<ShortLinkGroupRespDTO> list =  groupService.listGroup();
        return Results.success(list);
    }


    /**
     * 更新短链接分组信息
     * @param requestParam
     * @return
     */
    @PutMapping
    public Result<Void> update(@RequestBody ShortLinkGroupUpdateDTO requestParam){
        groupService.update(requestParam);
        return Results.success();
    }

    /**
     * 软删除短链接分组
     * @param gid
     * @return
     */
    @DeleteMapping
    public Result<Void> delete(String gid){
        groupService.delete(gid);
        return Results.success();
    }

    @PostMapping("/sort")
    public Result<Void> sortGroup(@RequestBody List<ShortLinkGroupSortReqDTO> requestParam){
        groupService.sortGroup(requestParam);
        return Results.success();
    }
}
